package com.ninja.sqlSession;

import com.ninja.config.XMLConfigBuilder;
import com.ninja.pojo.config.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

public class SqlSessionFactoryBuilder {

    private Configuration configuration;

    public SqlSessionFactoryBuilder() {
        this.configuration = new Configuration();
    }

    public SqlSessionFactory build(InputStream inputStream) throws PropertyVetoException, DocumentException {
        //1. 使用dom4j
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(inputStream);

        //2. 创建sqlsessionfactory对象  工厂类 生产sqlsession 会话对象
        return new DefalutSqlSessionFactory(configuration);
    }
}
